{  Statement: http://acmp.ru/?main=task&id_task=327
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i,n,x:longint;

function check(n : longint) : boolean;

var
    s:string;

begin
s := inttostr(n);
while length(s) < 6 do s := '0' + s;
result := ord(s[1]) + ord(s[2]) + ord(s[3]) = ord(s[4]) + ord(s[5]) + ord(s[6]);
end;
    
begin
reset(input, 'input.txt');
rewrite(output, 'output.txt');
read(n);
for i:=1 to n do begin
    read(x);
    if check(x - 1) or check(x + 1) then writeln('Yes') else writeln('No');
end;
end.